package com.pms.web;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ImgServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String img=request.getParameter("img");
		File file=new File("c:/upload",img);
		if(file.exists()){
			InputStream in=new FileInputStream(file);
			OutputStream out=response.getOutputStream();
			byte[] buffer= new byte[512];
			int len=-1;
			while((len=in.read(buffer))!=-1){
				out.write(buffer,0,len);
				
			}
			out.flush();
			in.close();
			out.close();
			
		}else{
			response.sendError(404);
			
		}
	}

}
